package com.mcptt.config.model;

import android.os.Parcel;
import android.os.Parcelable;

import java.io.File;

public class BootStrapSvrInfo implements Parcelable
{
	public static final String Default_Svr_Ip = "192.168.1.102";//MCS//SERVER DIFFERENT//
//	public static final String Default_Svr_Ip = "10.100.131.71";//TEKE//SERVER DIFFERENT//
	public static final int Default_Svr_Port = 8380;
//	public static final int Default_Http_Port = 8080;
	private String serverIp = null;
	private int port = Default_Svr_Port;
//	private String idmsHttpUrl = null;
	private String cmsHttpUrl = null;
	private String gmsHttpUrl = null;
	private String otaHttpUrl = null;



//	private String sbcUrl = null;
//	private String pfSipUrl = null;
//	private String cmsSipUrl = null;

	public BootStrapSvrInfo(String serverIp, int port)
	{
		this.serverIp = serverIp;
		this.port = port;
	}

	public void updateServerUrl(String cmsHttpUrl, String gmsHttpUrl, String uploadHttpUrl)
	{
		this.cmsHttpUrl = cmsHttpUrl;
		this.gmsHttpUrl = gmsHttpUrl;
		this.otaHttpUrl = uploadHttpUrl;
//		this.idmsHttpUrl = idmsHttpUrl;
//		this.sbcUrl = sbcUrl;
//		this.pfSipUrl = pfSipUrl;
//		this.cmsSipUrl = cmsSipUrl;
	}

	public String getServerIp()
	{
		return serverIp;
	}

	public int getPort()
	{
		return port;
	}
	public String getCmsHttpUrl() {
		return cmsHttpUrl;
	}

//	public String getGmsHttpUrl() {
//		return gmsHttpUrl;
//	}

//	public String getIdmsHttpUrl() {
//		return idmsHttpUrl;
//	}

//	public String getSbcUrl() {
//		return sbcUrl;
//	}

	public String toInitHttpUrl()
	{
		StringBuffer buffer = new StringBuffer("http://");
		buffer.append(serverIp).append(":");
		buffer.append(port);

		return buffer.toString();
	}

	public String toUploadHttpUrl(String androidId,String num)
	{
		return otaHttpUrl +"/ota/api/logUpload/CRSC_UE_LARGE_SCREEN/"+androidId+ File.separator+num+ File.separator +"index";
	}
	public String toUpgradeHttpUrl(String androidId,String num)
	{
		StringBuffer buffer = new StringBuffer("http://");
		buffer.append(serverIp).append(":");
		buffer.append(port);
		buffer.append("/ota/api/downloadReq/CRSC_UE_LARGE_SCREEN/");
		buffer.append(androidId).append(File.separator);
		buffer.append(num).append(File.separator);
		buffer.append("index");

		return buffer.toString();
	}
	public String getOtaHttpUrl() {
		return otaHttpUrl;
	}
	public String toCmsHttpUrl()
	{
		StringBuffer buffer = new StringBuffer("http://");
		buffer.append(serverIp).append(":");
		buffer.append(port);

		return buffer.toString();
	}
	
	public String toGmsHttpUrl()
	{
		StringBuffer buffer = new StringBuffer("http://");
		buffer.append(gmsHttpUrl).append("/");

		return buffer.toString();
	}

	public String toString()
	{
		StringBuffer buffer = new StringBuffer("ServerInfo:");
		buffer.append("serverIp = ").append(serverIp).append(",");
		buffer.append("port = ").append(port).append(",");
		buffer.append("cmsHttpUrl = ").append(cmsHttpUrl).append(",");
		buffer.append("gmsHttpUrl = ").append(gmsHttpUrl).append(",");
//		buffer.append("idmsHttpUrl = ").append(idmsHttpUrl).append(";");
		buffer.append("otaHttpUrl = ").append(otaHttpUrl).append(";");


		return buffer.toString();
	}

	public static final Parcelable.Creator<BootStrapSvrInfo> CREATOR = new Parcelable.Creator<BootStrapSvrInfo>() {
		public BootStrapSvrInfo createFromParcel(Parcel in) {
			return new BootStrapSvrInfo(in);
		}

		public BootStrapSvrInfo[] newArray(int size) {
			return new BootStrapSvrInfo[size];
		}
	};

	private BootStrapSvrInfo(Parcel in)
	{
		serverIp = getReadParcelableString(in.readString());
		port = in.readInt();
		cmsHttpUrl = getReadParcelableString(in.readString());
		gmsHttpUrl = getReadParcelableString(in.readString());
//		idmsHttpUrl = getReadParcelableString(in.readString());
		otaHttpUrl = getReadParcelableString(in.readString());
	}

	private String getWriteParcelableString(String str) {
		return (str == null) ? "null" : str;
	}
	private String getReadParcelableString(String str) {
		return str.equalsIgnoreCase("null") ? null : str;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeString(getWriteParcelableString(serverIp));
		dest.writeInt(port);
		dest.writeString(getWriteParcelableString(cmsHttpUrl));
		dest.writeString(getWriteParcelableString(gmsHttpUrl));
//		dest.writeString(getWriteParcelableString(idmsHttpUrl));
		dest.writeString(getWriteParcelableString(otaHttpUrl));
	}
}
